package au.com.fx.controllers;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import au.com.fx.contact.SigningUpUser;
import au.com.fx.contact.SigningUpUserRepository;

@Controller
public class AccountController {
	@Autowired
	SigningUpUserRepository signingUpUserRepository;
	
	@RequestMapping(value = "/account/create", method = RequestMethod.GET)
	public String showAccountForm() {
		return "create_account";
	}
	
	@ModelAttribute
	SigningUpUser signingUpUser(){
		return new SigningUpUser();
	}

	
	@RequestMapping(value= "/account/create", method = RequestMethod.POST)
	public String createAccount(@ModelAttribute("signingUpUser")  SigningUpUser user,
			ModelMap map){
		signingUpUserRepository.save(user);
		map.addAttribute("user", user.getName());
		return "home";
	}

}
